/*
 * User: Sebastian Schuth <sebastian.schuth@agimatec.de>
 * Date: 29.10.2008
 * Time: 13:18:35
 * Copyright (c) 2008 agimatec GmbH
 */
package com.agimatec.locators.predicate;

/**
 * LocatorPart matching the node with the given index.
 */
public class Index extends Predicate {
    private final int index;

    /**
     * Matches a node with the given index.
     * <b>Note: XPath index starts with 1, so to get the second node use "2" as index value.</b>
     *
     * @param index Index of the node that should get selected. Must be a positive, non-zero number
     */
    public Index(int index) {
        if (index < 1) throw new IllegalArgumentException("Must be a non-zero positive integer. XPath " +
                "indexes are NOT zero-based, so the first element has index 1");
        this.index = index;
    }

    public String locatorPartString(LocatorStringFactory factory) {
        return factory.getIndexPredicate(index).locatorString();
    }
}
